#!/bin/bash
#
# Create debian files from *.in files
#
# $1 = path to debian files
# $2 = fpc target (i386-linux)
# $3 = ppcXXX binary name (ppc386)
#
#set -x
if [ $# != 2 ]; then
  echo 'Usage : fixdeb <path> <target>'
  exit 1
fi

DEB_SUBST_PACKAGEVERSION=`dpkg-parsechangelog | sed -ne's,^Version: \(.*\),\1,p'`
DEB_SUBST_VERSION=`echo $DEB_SUBST_PACKAGEVERSION | sed -ne's,^\([0-9.]*\).*,\1,p'`
DEB_SUBST_DEBVERSION=`echo $DEB_SUBST_PACKAGEVERSION | awk -F '-' '{ print $NF }'`
DEB_SUBST_SVNPATH=`echo $DEB_SUBST_VERSION | awk -F '.' '{ print "release_"$1"_"$2"_"$3 }'`
DEB_SUBST_TARGET="$2"
DEB_SUBST_PACKAGESUFFIX=${PACKAGESUFFIX}

SUBST_CMD=`set | sed -n -e 's/^DEB_SUBST_\([A-Z_]\+\)=\(.*\)/-e s@\${\1}@\2@g/p'`

for i in $1/*.in
do
  j=`basename ${i} .in`
  sed ${SUBST_CMD} ${i} > $1/${j/./${PACKAGESUFFIX}.}
done
